 var Flippers = (function() {
    function Flippers(node, currentTime, nextTime){
        this.isFlipping = false;
        this.duration = 600
        this.flipNode = node
        this.frontNode = node.querySelector('.front')
        this.backNode = node.querySelector('.back')

        //设置要展示的值
        this.setFrontTime(currentTime)
        this.setBackTime(nextTime)
    }

    Flippers.prototype.setFrontTime = function (time) {
        this.frontNode.dataset.number = time
    }

    Flippers.prototype.setBackTime = function (time) {
        this.backNode.dataset.number = time
    }

    return Flippers
 }())


function getTimeFromDate(date) { //帮忙把这个字符串切出来
   return date.toTimeString().slice(0, 8).split(':').join('');
}

const flips = document.querySelectorAll('.flip')
const now = new Date()

//上一秒时间
const nowTimeStr = getTimeFromDate(new Date(now.getTime() - 1000))
//下一秒时间
const nextTimeStr = getTimeFromDate(now)
//遍历每个卡片，为每个卡片打造控制它的翻转函数
const flippers = Array.from(flips).map((flip, i) => {
        return  new Flippers(flip, nowTimeStr[i], nextTimeStr[i])
})

console.log(flippers);


setInterval(() => {
    const now = new Date()
    const nowTimeStr = getTimeFromDate(new Date(now.getTime() - 1000))
    const nextTimeStr = getTimeFromDate(now)
    for(let i = 0;i < flippers.length;i++){
        if (nowTimeStr[i] === nextTimeStr[i] ) {
            continue
        }
        flippers[i].flipDown(nowTimeStr[i],nextTimeStr[i])
    }

},1000)